// 类的访问修饰符
// public   允许内外部访问
// private  允许内部访问    不允许子类访问
// protected    允许内部及子类访问
// constructor 默认为public 若为private则不能被外部实例化 也不能够被继承

export {} // 确保跟其他示例没有成员冲突

class Person {
    public name: string
    private age: number
    protected gender: boolean
    constructor (name: string, age: number) {
        // TS当中需要明确声明其拥有的属性 不能动态添加
        this.name = name
        this.age = age
        this.gender = true
    }

    sayHi (msg: string): void{
        console.log(`I am ${name}, ${msg}`);
        console.log(this.age);
        
    }
}

class Student extends Person {
    private constructor (name: string, age: number) {
        super(name, age)
        console.log(this.gender);
        
    }

    static create (name: string, age: number) {
        return new Student(name, age)
    }
}

const tom = new Person('tom', 18)
console.log(tom.name);
// 访问私有成员会报错 只允许内部访问
// console.log(tom.age);
// console.log(tom.gender);

const jack = Student.create('jack', 18)

